Test whether a number is within 100 of 1000sΒΆ
Test whether a number is within 100 of 1000 or 2000.
def near_thousand(N):
return ((abs(1000 - N) <= 100) or (abs(2000 - N) <= 100))
print(near_thousand(1000))
print(near_thousand(900))
print(near_thousand(800))
print(near_thousand(2200))
Output:
True
True
False
False